<?php

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

require_once  __DIR__ . '/includes/authenticate.php';

if (isset($_SESSION['user_key'])) {

include_once __DIR__ . '/db_bb_connect.php';

$username = $_SESSION['username'];

$sql = "SELECT firstname, lastname, type, user_key FROM users WHERE username = '$username'";

  if ($db->query($sql)) {  
    } else {
      echo "Error: " . $sql . "<br>" . $db->error;
    }

  $result = $db->query($sql);
  $row = $result->fetch_assoc();

  $firstname = $row['firstname']; 
  $lastname = $row['lastname']; 
  $type = $row['type'];
  $playerID = $row['user_key'];

?>

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta charset="utf-8">
	<title>Basketbal <?= $type; ?> <?= $firstname; ?> <?= $lastname; ?></title>

  <link rel="stylesheet" type="text/css" href="./css/style.css">
 <link rel="icon" href="./images/basketball2.png" type="image/png"> 

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">

  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tokenfield/0.12.0/css/bootstrap-tokenfield.min.css">

  <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tokenfield/0.12.0/bootstrap-tokenfield.js"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  <script type="text/javascript" src="./js/bootstrap-tabcollapse.js"></script>
  <script type="text/javascript" src="./js/functions.js"></script>

</head>
<body>


<br>
<nav class="navbar navbar-inverse navbar-fixed-top navbar-expand-xl">
  <div class="container-fluid">
    <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#"><?= $firstname; ?> <?= $lastname; ?></a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
    <ul class="nav navbar-nav">
    	<?php

if ($type === 'Coach') {

	echo '<li><a href="#" class="mainpagebutton" name="home_coach">Home</a></li>';
	echo '<li><a href="#" class="mainpagebutton" name="home_player_admin">Player Home Viewer</a></li>';

 } else if ($type === 'Player'){

 	echo '<li><a href="#" class="mainpagebutton" name="home_player_loader">Home</a></li>';

}

?>
       <li><a href="#" name="game_stats_archive" class="mainpagebutton">Game Stats Archive</a></li>
       <li><a href="#" class="mainpagebutton" name="article_overview_player">Theory</a></li>
      

<?php

if ($type === 'Coach') { ?>

	<li><a href="#" name="actionpoints_team" class="mainpagebutton">Team Actionpoints</a></li>
	<li><a href="#" name="playerprofile" class="mainpagebutton">Player Profiles</a></li>
	<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">Game
      <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a class="mainpagebutton" href="#" name="addstats_bytotals">Add Game Stats - Totals</a></li>
      <li><a class="mainpagebutton" href="#" name="addstats_byquarter">Add Game Stats - By Quarter</a></li>
    </ul>
  </li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">Training
      <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a class="mainpagebutton" href="#" name="training_addpresence">Add Presence Stats</a></li>
      <li><a class="mainpagebutton" href="#" name="training_addftstats">Add FT Stats</a></li>
      <li><a class="mainpagebutton" href="#" name="training_addftladderstats">Add FT-ladder Stats</a></li>
      <li><a class="mainpagebutton" href="#" name="training_addshuttlerunstats">Add Shuttle-run Stats</a></li>
      <li><a class="mainpagebutton" href="#" name="training_addgeninfo">Add General Training Info</a></li>
      <li class="divider"></li>
      <li><a class="mainpagebutton" href="#" name="training_viewpresence">View Presence by Training</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewpresenceweek">View Presence by Week</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewpresencecumu">View Presence by Season</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewftstatsweek">View FT Stats by Week</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewftstatscumu">View FT Stats by Season</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewftladderstats">View FT-ladder Stats by Season</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewshuttlerunplayerstats">View Shuttle-run Stats by Player</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewshuttlerunteamstats">View Shuttle-run Stats by Team</a></li>
      <li><a class="mainpagebutton" href="#" name="training_viewgeninfo">View General Training Info</a></li>
    </ul>
  </li>

  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">Other Tools
      <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
              <li><a class="mainpagebutton" href="#" name="admin_addeditgameresults">Add/Edit Game Result</a></li>
              <li><a class="mainpagebutton" href="#" name="admin_addeditgamecomment">Add/Edit Game Comment</a></li>
              <li><a class="mainpagebutton" href="#" name="admin_viewgamecomment">View Game Comment</a></li>
              <li><a class="mainpagebutton" href="#" name="opponents">Opponents</a></li>
              <li><a class="mainpagebutton" href="#" name="teamgoals">Team Goals</a></li>
              <li class="divider"></li>
              <li><a class="mainpagebutton" href="#" name="admin_addnewplayer">Add New Player</a></li>
              <li><a class="mainpagebutton" href="#" name="admin_addnewteam">Add New Team</a></li>
              <li><a class="mainpagebutton" href="#" name="admin_addplayertocoachteam">Add Player to Coachteam</a></li>
               <li><a class="mainpagebutton" href="#" name="admin_addplayertoopponent">Add Player to Opponent team</a></li>
              <li><a class="mainpagebutton" href="#" name="admin_addopptoseason">Add Opponent to Season</a></li>
              <li><a class="mainpagebutton" href="#" name="admin_addgametoseason">Add Game to Season</a></li>              
              <li><a class="mainpagebutton" href="#" name="admin_addnewseason">Add New Season</a></li>
              <li class="divider"></li>
              <li><a class="mainpagebutton" href="#" name="teaminfo">Team Info</a></li>
              <li><a class="mainpagebutton" href="#" name="serverlog">Server Log</a></li>
              <li><a class="mainpagebutton" href="#" name="dataviewer">Data Viewer</a></li>
    </ul>
  </li>

<?php 

}

?>
      
    </ul>
    <ul class="nav navbar-nav navbar-right">
      <li>
        <a href="#" name="settings" class="mainpagebutton"> Settings</a>
      </li>
      <li>
           <a href="#" id="logout" name="logout">
            <span class="glyphicon glyphicon-log-in"></span> 
            Logout</a>
      </li>
    </ul>
  </div>
  </div>
</nav>

<div class="container-fluid" id="maindiv">
<div class="row">

<div class="col-lg-1 col-md-1 col-sm-1"></div>
<div class="col-lg-10 col-md-10 col-sm-10" id="content"> 

</div>
<div class="col-lg-1 col-md-1 col-sm-1"></div>


</div>
</div>



<?php 
if ( $type === 'Coach' ) { ?>

<script type="text/javascript"> 

window.onload = callPage("home_coach");

</script>

<?php

} else if ( $type === 'Player' ) {

	?>

<script type="text/javascript">
  
window.onload = callPage("home_player_loader");

</script>

	<?php
	} 
	 ?> 

</body>


</html>

<?php 

	
} else {
	echo "nothing here";
}

?>